<?php

namespace app\controller;
use app\model\information;
use app\model\user;
use app\BaseController;
use app\model\work;
use think\facade\Db;
use think\facade\Request;
use think\facade\Session;
use app\model\department;
use think\facade\View;
use think\Model;

class Workr extends BaseController
{
    public function index(){
        $d=new work();
        $key=Request::param('key');
        if(!empty($key)){
            $data=$d->search();
        }else{
            $data=$d->paginate(5);
        }
        $time=date('Y-m-d 07:00:00');
        $time3=date('Y-m-d 17:00:00');
        $time1=date('Y-m-d H:i:s');
        $time2=date('Y-m-d H:i:s');
        $r=$d->where('sb','>',$time)->count();
        $z=$d->where('xb','<',$time3)->count();
        View::assign(['data'=>$data,'r'=>$r,'time1'=>$time1,'time2'=>$time2,'z'=>$z,'name'=>Session::get('name')]);
        return View::fetch();
    }
    public function index1(){
        $d=new work();
        $key=Request::param('key');
        if(!empty($key)){
            $data=$d->search();
        }else{
            $data=$d->paginate(5);
        }
        $time=date('Y-m-d 07:00:00');
        $time3=date('Y-m-d 17:00:00');
        $time1=date('Y-m-d H:i:s');
        $time2=date('Y-m-d H:i:s');
        $r=$d->where('sb','>',$time)->count();
        $z=$d->where('xb','<',$time3)->count();
        $phone=Session::get('name');
        $d=new information();
        $data1=$d->where('phone','=',$phone)->find();
        View::assign(['xm'=>$data1['name'],'id'=>$data1['id'],'bm'=>$data1['department']]);
        View::assign(['data'=>$data,'r'=>$r,'time1'=>$time1,'time2'=>$time2,'z'=>$z]);
        return View::fetch();
    }
    public function insert(){
        $p=Request::post();
        $d=new work();
        $res=$d->insert($p);
//        $res=Db::table('subjecttype')->insert($p);
        if($res){
            return 1;
        }else{
            return 0;
        }

    }
    function update(){
        $data=Request::post();
        $d=new work();
        $res=$d->where('num',$data['num'])->update($data);
//        $res=Db::table('doctor')->update($data);
        if($res){
            return 1;
        }else{
            return 0;
        }
//        return ($res);
    }
    function edit(){
        $id=Request::get('id');
        $d=new work();
//        $data=$d->find($id);
        $data=$d->where('num',$id)->find();
        return json($data);
    }
    public function del(){
        $id=Request::param('id');
        $d=new work();
        $res=$d->where('num',$id)->delete();
        if($res){
            return 1;
        }else{
            return 0;
        }
    }
}